package cn.unknowpupil.init.mapper.system;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Mapper;

import cn.unknowpupil.init.domain.system.SysUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.security.core.userdetails.User;

import java.util.Date;
import java.util.List;

/**
 * Created at 2020-11-13 by  w10g <br>
 * Initialize SysUser  ... <br>
 *  用户信息表 数据持久层处理
 *
 * @author unknowpupil
 * @since 0.0.1
 */
@Mapper
public interface SysUserMapper extends BaseMapper<SysUser> {

    /**
     * 修改用户登录状态
     *
     * @param userId
     * @param loginIp
     * @param lastLoginDate
     * @return
     */
    boolean updateByUserId(@Param("userId") Long userId, @Param("loginIp") String loginIp, @Param("lastLoginDate") Date lastLoginDate);

    /**
     * 分页查询用户
     *
     * @param page
     * @param sysUser
     * @return
     */
    IPage<SysUser> page(@Param("page") IPage<SysUser> page, @Param("sysUser") SysUser sysUser);


    /**
     *
     * 如果自定义的方法还希望能够使用MP提供的Wrapper条件构造器，则需要如下写法
     *
     * @param userWrapper
     * @return
     */
    @Select("SELECT * FROM sys_user ${ew.customSqlSegment}")
    List<User> selectByMyWrapper(@Param(Constants.WRAPPER) Wrapper<User> userWrapper);

    /**
     * 和Mybatis使用方法一致
     * @param name
     * @return
     */
    @Select("SELECT * FROM sys_user where user_name = #{name}")
    List<User> selectByName(@Param("name") String name);
}
